-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Prohibit named tuple keys called 'apply' #24188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| untpd.Literal(Constant(nameIdx))), | ||
| pt) | ||
| if selName == nme.apply then | ||
| EmptyTree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the behavior of the following code now:
val boo: NamedTuple.NamedTuple[("_2", "apply"), (Int, Int)] = (1, 2)
println(boo.apply)I mean, that's too easy to bypass restrictions on named tuple field names. What error will be in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation doesn't apply to non-standard construction of named tuples (#23360). The compiler team decided that validation should only be applied to named tuples created with the spec (k:V) syntax. Either way of course it should not crash the compiler.
|
I think we can probably do a slightly different approach, in that we don't try to do member selection on a named tuple if that tuple defines the apply method. That would make the scheme water-tight even for tuples constructed by hand with |
Similar to scala#24188, but we now disallow `apply` members at tuple selection instead of tuple formation. This also works for hand-rolled tuples built using `NamedTuple(...)`. And it constitutes the minimal fix to avoid the recursion.
|
Replaced by #24191 |
Similar to scala#24188, but we now disallow `apply` members at tuple selection instead of tuple formation. This also works for hand-rolled tuples built using `NamedTuple(...)`. And it constitutes the minimal fix to avoid the recursion.
Similar to #24188, but we now disallow `apply` members at tuple selection instead of tuple formation. This also works for hand-rolled tuples built using `NamedTuple(...)`. And it constitutes the minimal fix to avoid the recursion.
Fixes #24021